package com.wtwd.campus.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wtwd.campus.dao.WarningRecordMapper;
import com.wtwd.campus.entity.OrgExpiration;
import com.wtwd.campus.entity.WarningRecord;
import com.wtwd.campus.service.WarningRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class WarningRecordServiceImpl implements WarningRecordService {
    @Autowired
    private WarningRecordMapper warningRecordMapper;
    @Override
    public Integer addWarningRecord(WarningRecord record) {
        return warningRecordMapper.addWarningRecord(record);
    }

    @Override
    public Integer addOrgExpirationList(List<OrgExpiration> list) {
        return warningRecordMapper.addOrgExpirationList(list);
    }

    @Override
    public List<OrgExpiration> getUnReadOrgExpirationMess() {
        return warningRecordMapper.getUnReadOrgExpirationMess();
    }

    @Override
    public Integer getUnReadCount() {
        return warningRecordMapper.getUnReadCount();
    }

    @Override
    public Map<String,Object> queryOrgExpirationByPage(Integer curPage,Integer pageSize) {
        //构建分页
        Page<List<OrgExpiration>> page = new Page<>(curPage, pageSize);
        IPage<OrgExpiration> result = warningRecordMapper.queryOrgExpirationByPage(page);
        Map<String,Object> map=new HashMap<>();
        map.put("total",result.getTotal());
        map.put("data",result.getRecords());
        return map;
    }

    @Override
    public Integer updateIfRead() {
        return warningRecordMapper.updateIfRead();
    }

}
